home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / tools / cdflist2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-11  |  58.7 KB  |  2,253 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                        CDFlist.  Part 2 of 2.
  4. *
  5. *  Version 2.0, 9-Mar-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  29-Jan-91, H Leckner    Original version (for CDF V2.0).
  10. *   V1.1   5-Feb-91, J Love    Modified error handling.
  11. *   V1.2  12-Feb-91, H Leckner    Fixed variable name handling.
  12. *   V1.3  13-Mar-91, H Leckner    Fixed attribute entry problem.
  13. *   V1.4  20-Mar-91, H Leckner    Fixed problem with large dimension sizes.
  14. *   V1.5  26-Mar-91, J Love    Cast malloc calls to proper type.  Fix for
  15. *                possible char array overwrite.
  16. *   V1.6   4-Apr-91, H Leckner    Fixed problem with filtering REAL8 values.
  17. *   V1.7   5-Jun-91, S Sudarsan Enhanced file/directory input handling
  18. *                               along with file_names.c.  Changed logical
  19. *                name for HELP directory.
  20. *   V1.8  25-Jun-91, J Love    Added QOP.  Added CDF_EPOCH as a data type.
  21. *             H Leckner    Added #include <sys/types.h>.
  22. *   V1.9  12-Jul-91, J Love    TRUE/FALSE.  Changed for Cray/UNICOS port.
  23. *             H Leckner    Added use of VALIDMIN/VALIDMAX for initial
  24. *                filters (if NSSDC_STANDARD).  Use 'Exit' &
  25. *                'ExitBAD'.
  26. *   V1.10 20-Sep-91, H Leckner    Fixed window labeling.  Modified for IBM-PC
  27. *             J Love    port.
  28. *   V1.11 11-Oct-91, H Leckner    Added ability to select more than 8
  29. *                variables.
  30. *   V2.0   9-Mar-91, H Leckner  Changed for IBM-RS6000 port.  IBM PC port.
  31. *                CDF V2.2.
  32. *
  33. ******************************************************************************/
  34.  
  35. #include <stdio.h>
  36. #include <math.h>
  37. #include <string.h>
  38.  
  39. #if defined(unix)
  40. #include <sys/types.h>
  41. #include <sys/stat.h>
  42. #else
  43. #if defined (vms)
  44. #include <descrip.h>
  45. #else
  46. #if defined(__MSDOS__)
  47. #include <dos.h>
  48. #endif
  49. #endif
  50. #endif
  51.  
  52. #include "cdfdist.h"
  53. #include "wfl.h"
  54. #include "kb_def.h"
  55. #include "utility.h"
  56. #include "cdflist.h"
  57.  
  58. void get_field(row_data, col, max_len, value, first_blank, value_entered)
  59. char        row_data[];
  60. int        col;
  61. int        max_len;
  62. char        value[];
  63. long int    *first_blank;
  64. long int    *value_entered;
  65. {
  66. long int    i;
  67. *first_blank = NOTTHERE;
  68. *value_entered = FALSE;
  69.  
  70. if(strlen(row_data) == 0)
  71.    {
  72.    value[0] = '\0';
  73.    return;
  74.    }
  75. for (i=col; i<col+max_len; i++)
  76.      {
  77.      value[i-col] = row_data[i-1];
  78.      if(row_data[i-1] != ' ')
  79.     *value_entered = TRUE;
  80.      else
  81.      {
  82.      if(*first_blank == NOTTHERE)*first_blank = i-col;
  83.      }
  84.      }
  85.  
  86. /*
  87. if there was a value entered and it is the maximum length tell the program
  88. that the first blank is the maximum length;
  89. */
  90. if(value_entered && *first_blank == NOTTHERE)*first_blank = max_len;
  91. value[max_len] = '\0';
  92. }
  93. void next_field(col_field, select_num, start_page, row, scroll, num_poss)
  94. long int    *col_field;
  95. long int    *select_num;
  96. long int    *start_page;
  97. int        *row;
  98. long int    *scroll;
  99. long int    num_poss;
  100. {
  101. if(*col_field > 3)
  102.    {
  103.    *col_field = 1;
  104.    (*select_num)++;
  105.    if(*select_num > num_poss)*select_num = 1;
  106.    (*row)++;
  107.    if(*row > 9)
  108.       {
  109.       *row = 9;
  110.       if(num_poss > 8)
  111.      {
  112.      (*start_page)++;
  113.      if(*start_page > num_poss)*start_page = 1;
  114.      *scroll = TRUE;
  115.      }
  116.       }
  117.    }
  118. else if(*col_field < 1)
  119.     {
  120.     *col_field = 3;
  121.     (*select_num)--;
  122.     if(*select_num < 1)*select_num = num_poss;
  123.     (*row)--;
  124.     if(*row < 2)
  125.        {
  126.        *row = 2;
  127.        if(num_poss > 8)
  128.           {
  129.           (*start_page)--;
  130.           if(*start_page < 1)*start_page = num_poss;
  131.           *scroll = TRUE;
  132.           }
  133.        }
  134.     }
  135. }
  136. long int check_var(display, var, num_poss)
  137. struct vid_struct    display[];
  138. char            var[];
  139. long int        num_poss;
  140. {
  141. char        mnemonic[CDFLIST_MAX_VAR_LENGTH];
  142. long int    first_blank;
  143. long int    check_len;                    /* V1.2 */
  144. long int    value_entered;
  145. long int    i;
  146. long int    elem;
  147. for(i=1; i <= num_poss; i++)
  148.     {
  149.     elem = i * 3;
  150. /*
  151. Copy Mnemonic
  152. */
  153.      get_field(display[elem].label, 6, CDFLIST_MAX_VAR_LENGTH, mnemonic,
  154.         &first_blank, &value_entered);
  155.      check_len = strlen(var);                    /* V1.2  */
  156.      if(first_blank > check_len)check_len = first_blank;
  157.      if(strncmp(var, mnemonic, check_len) == 0 && value_entered)
  158.     return(DUPLICATE);
  159.      }
  160. return(OK_RESP);
  161. }
  162. void CDFLIST_special_keydef(screen)
  163. struct            GLOBAL_struct    *screen;
  164. {
  165. char            key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
  166. char            key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
  167. /*
  168. Load up keypad definitions for selecting a menu item
  169. */
  170. key_line1[0] = '\0';
  171. key_line2[0] = '\0';
  172. strcat(key_line1,CNTRLM); strcat(key_line1, UP);strcat(key_line1, RET);
  173. strcat(key_line1,Qdes);
  174. strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);strcat(key_line2, HLP);
  175. CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
  176. }
  177. void CDFLIST_menu_keydef(screen)
  178. struct            GLOBAL_struct    *screen;
  179. {
  180. char            key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
  181. char            key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
  182. /*
  183. Load up keypad definitions for selecting a menu item
  184. */
  185. key_line1[0] = '\0';
  186. key_line2[0] = '\0';
  187. strcat(key_line1,CNTRLM); strcat(key_line1, UP);
  188. strcat(key_line1,PUP);strcat(key_line1,HLP);strcat(key_line1,Qdes);
  189. strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);
  190. strcat(key_line2,PDOWN);strcat(key_line2,RET);
  191. CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
  192. }
  193. void CDFLIST_load_discrete(values, num_values, col_field, DIS_display,
  194.            num_rows, paste_col)
  195. char            values[];
  196. long int        num_values;
  197. long int         col_field;
  198. struct vid_struct      *DIS_display;
  199. long int        *num_rows;
  200. long int        *paste_col;
  201. {
  202. long int        i;
  203.  
  204. for (i=0; i<num_values; i++)
  205.      {
  206.     DIS_display[i].row = 1;
  207.     DIS_display[i].col = 1;
  208.     strcpy(DIS_display[i].label,&values[i*MINMAX_SIZE]);
  209.     DIS_display[i].field_col = 1;
  210.      }
  211. if((num_values+ROW_OFFSET) > DIS_ROWS)
  212.    *num_rows = DIS_ROWS;
  213. else
  214.    *num_rows = num_values + ROW_OFFSET;
  215.  
  216. if(col_field == 3)
  217.    *paste_col = DISMIN_COL_PASTE;
  218. else
  219.    *paste_col = DISMAX_COL_PASTE;
  220. }
  221. CDFstatus CDFLIST_read_VAR(display, possible, num_poss, select, num_select)
  222. struct vid_struct       display[];
  223. struct variable_struct  possible[];
  224. long int        num_poss;
  225. struct variable_struct  select[];
  226. long int        *num_select;
  227. {
  228. CDFstatus        rcode;
  229. long int        i, j, ii;
  230. long int        found;
  231. long int        len;
  232. long int        field_num;
  233. double            min_max;
  234. char            value[41];
  235. long int        first_blank, check_len;            /* V1.2 */
  236. long int        mnemonic_entered;
  237. long int        min_filter_entered;
  238. long int        max_filter_entered;
  239. Boolean            echeck;
  240. rcode = 0;
  241. *num_select = 0;
  242. field_num = 0;
  243. for (j=1; j<=num_poss; j++)
  244.     {
  245.     field_num = field_num + 3;
  246. /*
  247. EXTRACT the VARIABLE name
  248. */
  249.     get_field(display[field_num].label+display[field_num].field_col-1, 1,
  250.           CDFLIST_MAX_VAR_LENGTH, value, &first_blank, &mnemonic_entered);
  251.     if(mnemonic_entered)
  252.        {
  253. /*
  254. VARIABLE NAME WAS ENTERED
  255. */
  256. /*
  257. LOOK in the array of possible variables for the column number
  258. */
  259.        found = FALSE;
  260.        for(i=0; i<num_poss && !found; i++)
  261.       {
  262.       check_len = strlen(possible[i].var_mnemonic);        /* V1.2 */
  263.       if(first_blank > check_len ||
  264.          first_blank == CDFLIST_MAX_VAR_LENGTH)check_len = first_blank;
  265.           if(strncmp(possible[i].var_mnemonic, value, check_len) == 0)
  266.          {
  267.                 strcpy(select[*num_select].var_mnemonic, 
  268.             possible[i].var_mnemonic);
  269.              select[*num_select].var_num = possible[i].var_num;
  270.          select[*num_select].record_variance =
  271.           possible[i].record_variance;
  272.          for (ii=0; ii< 10; ii++)
  273.                   select[*num_select].dim_variances[ii] = 
  274.                 possible[i].dim_variances[ii];
  275.              select[*num_select].num_bytes = possible[i].num_bytes;
  276.              select[*num_select].num_values= possible[i].num_values;
  277.              select[*num_select].dim_num = possible[i].dim_num;
  278.          /*
  279.          strcpy(select[*num_select].header_name,
  280.             possible[i].header_name);
  281.          */
  282.          select[*num_select].var_mnemonic_len=possible[i].var_mnemonic_len;
  283.              select[*num_select].bin_value = possible[i].bin_value;
  284.              select[*num_select].data_type = possible[i].data_type;
  285.          select[*num_select].scalar = possible[i].scalar;
  286.          found = TRUE;
  287.          }
  288.       }
  289.  
  290. /*
  291. RETRIEVE MINIMUM VALUES
  292. */
  293.        if(select[*num_select].data_type != CDF_EPOCH)
  294.       len = MINMAX_SIZE;
  295.        else
  296.       len = EPOCH_WIDTH;
  297.        get_field(display[field_num+1].label, 
  298.          display[field_num+1].field_col-display[field_num+1].col+1,
  299.                 len,value,&first_blank, &min_filter_entered);
  300.        if(min_filter_entered)
  301.       {
  302.       if(select[*num_select].data_type != CDF_EPOCH)
  303.              sscanf(value,"%lf",&min_max);
  304.           else
  305.          echeck = check_epoch(value, &min_max);
  306.       select[*num_select].min = min_max;
  307.       }
  308. /*
  309. NOW RETRIEVE MAXIMUM VALUE
  310. */
  311.        get_field(display[field_num+2].label,
  312.          display[field_num+2].field_col-display[field_num+2].col+1,
  313.                    len,value,&first_blank, &max_filter_entered);
  314.        if(max_filter_entered)
  315.       {
  316.       if(select[*num_select].data_type != CDF_EPOCH)
  317.          {
  318.              sscanf(value,"%lf",&min_max);
  319.           echeck = TRUE;
  320.              }
  321.       else
  322.          echeck = check_epoch(value, &min_max);
  323.       if(echeck)select[*num_select].max = min_max;
  324.       }
  325. /*
  326. Check to see if a filter was entered for this variable or
  327. if only 1 value was entered
  328. */
  329.        if(min_filter_entered && !max_filter_entered)
  330.         {
  331.             select[*num_select].max = select[*num_select].min;
  332.           select[*num_select].filter = TRUE;
  333.         }
  334.        else if(!min_filter_entered && max_filter_entered)
  335.         {
  336.           select[*num_select].min = select[*num_select].max;
  337.         select[*num_select].filter = TRUE;
  338.         }
  339.        else if(!min_filter_entered && !max_filter_entered)
  340.         {
  341.           select[*num_select].min = select[*num_select].max;
  342.           select[*num_select].filter = FALSE;
  343.         }
  344.        else 
  345.         select[*num_select].filter = TRUE;
  346. /*
  347. If there was a filter entered see if the USER entered a 
  348. Minimum value  > Maximum value
  349. */
  350.  
  351.        if((select[*num_select].filter) &&
  352.       (select[*num_select].min > select[*num_select].max))
  353.       {
  354.       *num_select = 0;
  355.       rcode = 1;
  356.       return(rcode);
  357.       }
  358.        else
  359.           *num_select = *num_select + 1;
  360.        }
  361.      }
  362. return(rcode);
  363. }
  364. void CDFLIST_filter(select, num_select, data_values, check_scalar, valid)
  365. struct variable_struct  select[];
  366. long int        num_select;
  367. union mixed        data_values[];
  368. long int        check_scalar;
  369. long int        *valid;
  370. {
  371. long int        i;
  372. double            value;
  373.  
  374. *valid = TRUE;
  375. for (i = 0; i < num_select; i++)
  376.   {
  377.   if(select[i].scalar == check_scalar)
  378.      {
  379.      switch(select[i].data_type)
  380.            {
  381.            case CDF_REAL4:
  382.            case CDF_FLOAT:
  383.                 value = (double) data_values[i].r4;
  384.            break;
  385.            case CDF_REAL8:         
  386.            case CDF_DOUBLE:
  387.            case CDF_EPOCH:
  388.                 value = data_values[i].r8;
  389.            break;
  390.            case CDF_INT4:         
  391.                 value = (double) data_values[i].i4;
  392.            break;
  393.            case CDF_UINT4:
  394.                 value = (double) data_values[i].ui4;
  395.            break;
  396.            case CDF_INT2:         
  397.                 value = (double) data_values[i].i2;
  398.            break;
  399.            case CDF_UINT2:
  400.                 value = (double) data_values[i].ui2;
  401.            break;
  402.            case CDF_BYTE:
  403.            case CDF_INT1:
  404.                 value = (double) data_values[i].byte;
  405.            break;
  406.            case CDF_UINT1:
  407.                 value = (double) data_values[i].ubyte;
  408.            }
  409.            if((select[i].filter) &&
  410.                   (value < select[i].filter_min ||
  411.                    value > select[i].filter_max))*valid = FALSE;
  412.      }
  413.   }
  414. }
  415.  
  416. CDFstatus CDFLIST_put_CDF(new_CDF, record_num, indices, select,
  417.             num_select, data_values)
  418. struct CDF_struct      *new_CDF;
  419. long int        record_num;
  420. long int        indices[10];
  421. struct variable_struct  select[];
  422. long int        num_select;
  423. union  mixed        data_values[];
  424. {
  425. long int    i;
  426. CDFstatus     rcode;
  427. /*
  428. PUT VARIABLES INTO CDF
  429. */
  430.  
  431. for (i = 0; i < num_select; i++)
  432. {
  433. if(select[i].rcode >= CDF_OK)                    /* V1.1 */
  434.      {
  435.      switch (select[i].data_type)
  436.     {
  437.     case CDF_REAL4:
  438.     case CDF_FLOAT:
  439.          rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
  440.          indices, &data_values[i].r4);
  441.          break;
  442.     case CDF_REAL8:
  443.     case CDF_DOUBLE:
  444.     case CDF_EPOCH:
  445.          rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
  446.          indices, &data_values[i].r8);
  447.          break;
  448.     case CDF_INT4:
  449.     case CDF_UINT4:
  450.          rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
  451.          indices, &data_values[i].i4);
  452.          break;
  453.     case CDF_INT2:
  454.     case CDF_UINT2:
  455.          rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
  456.          indices, &data_values[i].i2);
  457.          break;
  458.     case CDF_BYTE:
  459.     case CDF_INT1:
  460.     case CDF_UINT1:
  461.          rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
  462.          indices, &data_values[i].byte);
  463.          break;
  464.     case CDF_CHAR:
  465.     case CDF_UCHAR:
  466.          rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
  467.          indices, data_values[i].string);
  468.     }
  469.      }
  470. }/*var loop*/
  471. return(rcode);
  472. }
  473. CDFstatus CDFLIST_get_discrete(CDF_id, dim_num, var_id, data_type,
  474.         num_values, bin_values, char_values)
  475. long int        CDF_id;
  476. long int        dim_num;
  477. long int        var_id;
  478. long int        data_type;
  479. long int        num_values;
  480. double            bin_values[];
  481. char            *char_values;
  482. {
  483. long int        indices[10];
  484. char            temp_val[50];
  485. long int        i;
  486. long int        record_num;
  487. CDFstatus        rcode;
  488. union     mixed         temp;
  489.  
  490. record_num = 0;
  491. for (i=0; i < 10; i++)
  492.      indices[i] = 0;
  493. for (i=0; i < num_values; i++)
  494.      {
  495.      indices[dim_num-1]=i;
  496.      switch(data_type)
  497.     {
  498.     case CDF_REAL4:
  499.     case CDF_FLOAT:
  500.          rcode = CDFvarGet(CDF_id, var_id, record_num,
  501.          indices, &temp.r4);
  502.          bin_values[i] = r4_r8(&temp.r4);
  503.          if(bin_values[i] < -1.e12 ||
  504.         bin_values[i] >  1.e12)
  505.         sprintf(temp_val,"%e",bin_values[i]);
  506.          else
  507.         sprintf(temp_val,"%f",bin_values[i]);
  508.          break;
  509.     case CDF_REAL8:
  510.     case CDF_DOUBLE:
  511.     case CDF_EPOCH:
  512.          rcode = CDFvarGet(CDF_id, var_id, record_num,
  513.          indices, &temp.r8);
  514.          sprintf(temp_val,"%f",temp.r8);
  515.          bin_values[i] = temp.r8;
  516.          if(bin_values[i] < -1.e12 ||
  517.         bin_values[i] >  1.e12)
  518.         sprintf(temp_val,"%e",bin_values[i]);
  519.          else
  520.         sprintf(temp_val,"%f",bin_values[i]);
  521.          break;
  522.     case CDF_INT4:
  523.          rcode = CDFvarGet(CDF_id, var_id, record_num,
  524.          indices, &temp.i4);
  525.          sprintf(temp_val,"%ld",temp.i4);
  526.          bin_values[i] = (double) temp.i4;
  527.          break;
  528.     case CDF_UINT4:
  529.          rcode = CDFvarGet(CDF_id, var_id, record_num,
  530.          indices, &temp.ui4);
  531.          sprintf(temp_val,"%lu",temp.ui4);
  532.          bin_values[i] = (double) temp.ui4;
  533.          break;
  534.     case CDF_INT2:
  535.          CDFvarGet(CDF_id, var_id, record_num,
  536.          indices, &temp.i2);
  537.          sprintf(temp_val,"%d",temp.i2);
  538.          bin_values[i] = (double) temp.i2;
  539.          break;
  540.     case CDF_UINT2:
  541.          CDFvarGet(CDF_id, var_id, record_num,
  542.          indices, &temp.ui2);
  543.          sprintf(temp_val,"%u",temp.ui2);
  544.          bin_values[i] = (double) temp.ui2;
  545.          break;
  546.     case CDF_BYTE:
  547.     case CDF_INT1:
  548.          rcode = CDFvarGet(CDF_id, var_id, record_num,
  549.          indices, &temp.byte);
  550.          sprintf(temp_val,"%d",temp.byte);
  551.          bin_values[i] = (double) temp.byte;
  552.          break;
  553.     case CDF_UCHAR:
  554.     case CDF_UINT1:
  555.          rcode = CDFvarGet(CDF_id, var_id, record_num,
  556.          indices, &temp.ubyte);
  557.          sprintf(temp_val,"%u",temp.ubyte);
  558.          bin_values[i] = (double) temp.ubyte;
  559.     }
  560.        temp_val[MINMAX_SIZE-1] = '\0';
  561.        zero_replace(temp_val);
  562.        strcpy(&char_values[i*MINMAX_SIZE], temp_val);
  563.      }
  564. return(rcode);
  565. }
  566. void CDFLIST_output(screen, CDF, out_file, field_num)
  567. struct        GLOBAL_struct    *screen;
  568. struct        CDF_struct    *CDF;
  569. FILE        **out_file;
  570. long int    *field_num;
  571. {
  572. long int    i, len;
  573. int        ok;
  574. int        termcode;
  575. char        default_name[15],display_name[15];
  576. char        mes[MES_COLUMNS-COL_OFFSET];
  577. static        char file_mes[] =
  578. "Enter File Name w/ NO EXTENSION or hit <CR> for default ";
  579. static        char CDF_mes[] =
  580. "Enter CDF  Name w/ NO EXTENSION ";
  581. static        char dot_lis[] = ".lis";
  582. static        char file_error[] =
  583. "Error opening output file, using output to TERMINAL";
  584.  
  585. CDFLIST_menu_keydef(screen);
  586. CDFLIST_select_menu_item(S.OUT_vid, S.MES_vid, &C.output,
  587. OUT_display, OUT_NUM_ELEMENTS, OUT_ROWS, OUT_COLUMNS, OUT_ROW_PASTE,
  588. OUT_COL_PASTE, MENU, &termcode);
  589. if(termcode != KB_CTRL_F && termcode != QUIT)
  590.    {
  591.    CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM-1,
  592.    OUT_display[C.output-1].label, OUT_COLUMNS-COL_OFFSET, REVERSE);
  593.    if(C.output != TERMIN)
  594.       {
  595.       if(C.output != CDFOUT)
  596.      strcpy(CDF_display[CDF_NUM_ELEMENTS-1].label, "File Name ");
  597.       else
  598.      strcpy(CDF_display[CDF_NUM_ELEMENTS-1].label, "CDF  Name ");
  599.       load_vid_element(S.CDF_vid, CDF_display, CDF_NUM_ELEMENTS);
  600.       for(i=0; i < 14; i++)
  601.          display_name[i] = 32;
  602.       if(C.output != CDFOUT)
  603.      {
  604.      CDFLIST_default_name(C.CDF_name, default_name);
  605.      strcpy(display_name, default_name);
  606.      }
  607.       else
  608.       default_name[0] = '\0';
  609.       display_name[14] = '\0';
  610.       CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM+1-1,
  611.       display_name, 8, REVERSE);
  612.       mes[0] = '\0';
  613.       if(C.output == CDFOUT)
  614.      strcpy(mes, CDF_mes);
  615.       else
  616.      {
  617.      strcpy(mes, file_mes);
  618.      strcat(mes, default_name);
  619.      strcat(mes, dot_lis);
  620.      }
  621.       CDFLIST_put_message(S.MES_vid, mes, NOBELL, NORMAL, NOPAUSE);
  622.       strcpy(C.file_name, default_name);
  623.       len = strlen(C.file_name);
  624.       for (i=len; i < 20; i++)
  625.     C.file_name[i] = '\0';
  626.       ok = FALSE;
  627.       while(!ok)
  628.     {
  629.     input_field(S.CDF_vid, C.file_name, OUT_NAME_ROW, OUT_NAME_COL,
  630.             OUT_NAME_LEN, &termcode);
  631.     if(C.file_name[0] != '\0')ok = TRUE;
  632.     }
  633.       CDFLIST_check_name(C.file_name);
  634.       if(C.output != CDFOUT)
  635.      {
  636.      strcat(C.file_name, dot_lis);
  637. /*
  638. OPEN THE FILE
  639. */
  640.      *out_file = fopen(C.file_name, "w");
  641.       if(*out_file == NULL)
  642.          {
  643.          CDFLIST_put_message(S.MES_vid, file_error, RINGBELL, NORMAL,
  644.                 NOPAUSE);
  645.          C.output = TERMIN;
  646.          CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM-1,
  647.          OUT_display[C.output-1].label, 14, REVERSE);
  648.          }
  649.      }
  650.       }
  651.       else
  652.     {
  653.       begin_display_update(S.CDF_vid);
  654.       erase_display(S.CDF_vid,
  655.         CDF_display[CDF_NUM_ELEMENTS-1].row,
  656.         CDF_display[CDF_NUM_ELEMENTS-1].col,
  657.         CDF_display[CDF_NUM_ELEMENTS-1].row, CDF_COLUMNS-COL_OFFSET);
  658. #if defined(vms)
  659.      end_display_update(S.CDF_vid);
  660. #else
  661.      end_display_update_nobox(S.CDF_vid);
  662. #endif
  663.     }
  664.       (*field_num)++;
  665.    }
  666.    else
  667.       CDFLIST_field_menu(screen, field_num);
  668. }
  669.  
  670. void CDFLIST_default_name(string, default_name)
  671. char        string[];
  672. char        default_name[];
  673. {
  674.  
  675. #if defined(unix)
  676. /*
  677. UNIX check for slash to see if a directory name is part of the CDF name
  678. */
  679. if(strchr(string, '/') != NULL)
  680. /*
  681. Copy from last occurence of the slash to end of string to pick out just CDF name
  682. */
  683.    strcpy(default_name, strrchr(string, '/')+1);
  684. else
  685. /*
  686. No directory found in string
  687. */
  688.    strcpy(default_name, string);
  689. #endif
  690.  
  691. #ifdef vms
  692. /*
  693. VMS first check for Right Bracket to see if a directory name
  694. is part of the CDF name
  695. */
  696. if(strchr(string, ']') != NULL)
  697.    strcpy(default_name, strrchr(string, ']')+1);
  698. /*
  699. VMS No right bracket check for a logical name with a colen to see if a
  700. directory name is part of the CDF name
  701. */
  702. else if(strchr(string, ':') != NULL)
  703.    strcpy(default_name, strrchr(string, ':')+1);
  704. else
  705. /*
  706. No directory found in string
  707. */
  708.    strcpy(default_name, string);
  709. #endif
  710.  
  711. /*  Patch for CD-ROMs */
  712. #ifdef __MSDOS__
  713. strcpy(default_name, "C:\\");
  714. if(strchr(string, '\\') != NULL)
  715.    strcat(default_name, strrchr(string, '\\')+1);
  716. else if(strchr(string, ':') != NULL)
  717.    strcat(default_name, strrchr(string, ':')+1);
  718. else
  719.    strcat(default_name, string);
  720. #endif
  721.  
  722. /*  Comment out the old
  723. #ifdef __MSDOS__
  724. if(strchr(string, '\\') != NULL)
  725.    strcpy(default_name, strrchr(string, '\\')+1);
  726. else if(strchr(string, ':') != NULL)
  727.    strcpy(default_name, strrchr(string, ':')+1);
  728. else
  729.    strcpy(default_name, string);
  730. #endif
  731. */
  732.  
  733. /*
  734. Default name will be 14 characters or less to allow for output device specific
  735. extension
  736. */
  737. if(strlen(default_name) > 14)default_name[14] = '\0';
  738. }
  739.  
  740. void CDFLIST_clear_row(vid, display, start_elem, end_elem, end_col)
  741. WINDOWid         vid;
  742. struct    vid_struct    display[];
  743. int            start_elem;
  744. int            end_elem;
  745. int            end_col;
  746. {
  747. long int        i;
  748.  
  749. int            row, col;
  750. for (i=start_elem; i<=end_elem; i++)
  751.      {
  752.      row = display[i-1].row;
  753.      col = display[i-1].field_col;
  754.      erase_display(vid, row, col, row, end_col);
  755.      }
  756. }
  757. void CDFLIST_file_header(CDF, select, num_select, fptr)
  758. struct    CDF_struct    *CDF;
  759. struct variable_struct  select[];
  760. long int        num_select;
  761. FILE            *fptr;
  762. {
  763. long int        i;
  764. fprintf(fptr," CDF NAME = %s\n\n",C.CDF_name);
  765. fprintf(fptr," VARIABLES AND SPECIFIED RANGES \n");
  766. fprintf(fptr,
  767. " ----------------------------------------------------------------------");
  768. fprintf(fptr,"------\n");
  769. for (i = 0; i < num_select; i++)
  770.        {
  771.        fprintf(fptr," %-19s ",select[i].var_mnemonic);
  772.        if(select[i].filter)
  773.      {
  774.      if(select[i].data_type == CDF_EPOCH)
  775.         {
  776.         ep.tSince0 = select[i].min;
  777.         if(SO.EPOCH_format == EPOCHFORM_DEF)
  778.            fprintf(fptr, " %s",epochString(&ep));
  779.         else
  780.            fprintf(fptr, " %s",epochString1(&ep));
  781.  
  782.         ep.tSince0 = select[i].max;
  783.         if(SO.EPOCH_format == EPOCHFORM_DEF)
  784.            fprintf(fptr, " %s",epochString(&ep));
  785.         else
  786.            fprintf(fptr, " %s",epochString1(&ep));
  787.  
  788.         }
  789.      else
  790.         {
  791.         if(select[i].min < -1.e12 ||
  792.            select[i].min > 1.e12)
  793.            fprintf(fptr, " %13.6e",select[i].min);
  794.         else
  795.            fprintf(fptr," %13.*f",precision(select[i].min),select[i].min);
  796.         if(select[i].max < -1.e12 ||
  797.            select[i].max >  1.e12)
  798.            fprintf(fptr, " %13.6e",select[i].max);
  799.         else
  800.            fprintf(fptr, " %13.*f",precision(select[i].max),select[i].max);
  801.         }
  802.        }
  803.        fprintf(fptr, "\n");
  804.        }
  805. }
  806. void CDFLIST_help(screen)
  807. struct        GLOBAL_struct    *screen;
  808. {
  809. long int         dummy;
  810. struct vid_struct      *HELP_display;
  811. long int        help_num_elements = 0;
  812. long int        i, len;
  813. int            tcode;
  814. static char        help_mes[] = "Press Return key when done";
  815. static char        help_error_mes[] = "Help not available ";
  816. static char        help_error_mal[] = "Help not available, malloc error ";
  817. char            key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
  818. char                   key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
  819. char            temp[80];
  820. int            help_rows, help_columns, paste_col;
  821. int            max_len;
  822. static int        first = TRUE;
  823. if(HELP_ptr != NULL)
  824.    {
  825. /*
  826. READ text until complete and load into a vid structure
  827. */
  828.    max_len = 0;
  829.    fseek(HELP_ptr, 0l, SEEK_SET);
  830.    while (fgets(temp,80,HELP_ptr) != NULL)
  831.       {
  832.       help_num_elements++;
  833.       len = lastc(temp);
  834.       if(len > max_len)max_len = len;
  835.       }
  836.    if(help_num_elements > HELP_ROWS)
  837.       help_rows = HELP_ROWS;
  838.    else
  839.       help_rows = help_num_elements+ROW_OFFSET;
  840.  
  841.    if(max_len > HELP_COLUMNS)
  842.       help_columns = HELP_COLUMNS;
  843.    else
  844.       help_columns = max_len+COL_OFFSET;
  845.  
  846.    paste_col = (80-help_columns)/2+1;
  847.  
  848.    if(first)
  849.       create_virtual_display(help_rows, help_columns, &S.HELP_vid, BORDER, BOLD);
  850.    first = FALSE;
  851.    HELP_display = (struct vid_struct *)
  852.           malloc(help_num_elements * sizeof(struct vid_struct));
  853.    if(HELP_display == NULL)
  854.       {
  855.       CDFLIST_put_message(S.MES_vid, help_error_mal, RINGBELL, NORMAL,
  856.         NOPAUSE);
  857.       return;
  858.       }
  859.    fseek(HELP_ptr, 0l, SEEK_SET);
  860.    i=0;
  861.    for(i=0; i <help_num_elements; i++)
  862.     {
  863.     fgets(temp,80,HELP_ptr);
  864.     HELP_display[i].row = 1;
  865.     HELP_display[i].col = 1;
  866.     len = lastc(temp) - 1;
  867.     strncpy(HELP_display[i].label,temp,len);
  868.     HELP_display[i].label[len] = '\0';
  869.     }
  870. /*
  871. LOAD in the keypad definitions for this option
  872. */
  873.     key_line1[0] = '\0'; key_line2[0] = '\0';
  874.     strcat(key_line1, UP); strcat(key_line1,PUP);
  875.     strcat(key_line2, DOWN);strcat(key_line2,PDOWN);
  876.     strcat(key_line2,CNTRLW);
  877.     CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
  878.     CDFLIST_put_message(S.MES_vid, help_mes, NOBELL, NORMAL, NOPAUSE);
  879. /*
  880. Display the HELP screen
  881. */
  882.     CDFLIST_select_menu_item(S.HELP_vid, S.MES_vid,
  883.     &dummy, HELP_display, help_num_elements, help_rows, help_columns,
  884.     HELP_ROW_PASTE, paste_col, HELP_MENU, &tcode);
  885.     free(HELP_display);
  886.    }
  887. else
  888.    CDFLIST_put_message(S.MES_vid, help_error_mes, RINGBELL, NORMAL, NOPAUSE);
  889. }
  890. int lastc(buf)
  891. char    *buf;
  892. {
  893. int done = FALSE;
  894. int i,j;
  895. int end;
  896. i = strlen(buf) + 1;
  897. end = i;
  898. j = 0;
  899. while(j < end && !done)
  900.       {
  901.       if(!isgraph(buf[i-1]))
  902.      done = TRUE;
  903.       else
  904.      j++; i--;
  905.       }
  906. return(i);
  907. }
  908. void CDFLIST_field_menu(screen, option)
  909. struct        GLOBAL_struct    *screen;
  910. long int    *option;
  911. {
  912. long int    cont;
  913. int        tcode;
  914. long int    temp;
  915. temp = *option+1;
  916. cont = CONTINUE;
  917. while(cont != DONE)
  918.       {
  919. /*
  920. Choose the particular field you wish to be in
  921. */
  922.       CDFLIST_menu_keydef(screen);
  923.       CDFLIST_select_menu_item(S.FIELD_vid, S.MES_vid, &temp,
  924.       FIELD_display, FIELD_NUM_ELEMENTS, FIELD_ROWS, FIELD_COLUMNS,
  925.       FIELD_ROW_PASTE, FIELD_COL_PASTE, MENU, &tcode);
  926.       *option = temp-1;
  927.       if(*option == HELP_FIELD)
  928.      CDFLIST_help(screen);
  929.       else if(*option == SPECIAL_OPT_FIELD)
  930.           CDFLIST_special_options(screen);
  931.       else
  932.      cont = DONE;
  933.        }
  934. }
  935. void CDFLIST_open_screen(screen)
  936. struct    GLOBAL_struct    *screen;
  937. {
  938. create_pasteboard();
  939. #if defined(vms)
  940. begin_pasteboard_update();
  941. #endif
  942. create_virtual_display(CDF_ROWS, CDF_COLUMNS, &S.CDF_vid, BORDER, BOLD);
  943. paste_virtual_display(S.CDF_vid, CDF_ROW_PASTE, CDF_COL_PASTE);
  944. #if defined(unix)
  945. begin_display_update(S.CDF_vid);
  946. #endif
  947. load_vid(S.CDF_vid, CDF_display, 0, CDF_NUM_ELEMENTS-1, NO_label);
  948. #if defined(unix)
  949. end_display_update(S.CDF_vid);
  950. #endif
  951. create_virtual_display(VAR_ROWS, VAR_COLUMNS, &S.VAR_vid, BORDER, BOLD);
  952. paste_virtual_display(S.VAR_vid, VAR_ROW_PASTE, VAR_COL_PASTE);
  953. create_virtual_display(KEY_ROWS, KEY_COLUMNS, &S.KEY_vid, BORDER, BOLD);
  954. paste_virtual_display(S.KEY_vid, KEY_ROW_PASTE, KEY_COL_PASTE);
  955. create_virtual_display(MES_ROWS, MES_COLUMNS, &S.MES_vid, BORDER, BOLD);
  956. paste_virtual_display(S.MES_vid, MES_ROW_PASTE, MES_COL_PASTE);
  957. create_virtual_display(OUT_ROWS, OUT_COLUMNS, &S.OUT_vid, BORDER, BOLD);
  958. create_virtual_display(FIELD_ROWS, FIELD_COLUMNS, &S.FIELD_vid,
  959. BORDER, BOLD);
  960. create_virtual_display(DIS_ROWS, DIS_COLUMNS, &S.DIS_vid, BORDER, BOLD);
  961. create_virtual_display(DIR_ROWS, DIR_COLUMNS, &S.DIR_vid, BORDER, BOLD);
  962. create_virtual_display(HELP_ROWS, HELP_COLUMNS, &S.HELP_vid, BORDER, BOLD);
  963. create_virtual_display(SPECIAL_ROWS, SPECIAL_COLUMNS, &S.SPECIAL_vid,
  964.             BORDER, BOLD);
  965. create_virtual_display(EPOCHFORMAT_ROWS, EPOCHFORMAT_COLUMNS,
  966.             &S.EPOCHFORMAT_vid, BORDER, BOLD);
  967. /*
  968. create_virtual_display(VARFORMAT_ROWS, VARFORMAT_COLUMNS,
  969.             &S.VARFORMAT_vid, BORDER, BOLD);
  970. create_virtual_display(MINMAX_ROWS, MINMAX_COLUMNS, &S.MINMAX_vid,
  971.             BORDER, BOLD);
  972. create_virtual_display(FILTER_ROWS, FILTER_COLUMNS, &S.FILTER_vid,
  973.             BORDER, BOLD);
  974. create_virtual_display(FILLVALUE_ROWS, FILLVALUE_COLUMNS, &S.FILLVALUE_vid,
  975.             BORDER, BOLD);
  976. */
  977. create_virtual_display(VARSELECT_ROWS, VARSELECT_COLUMNS, &S.VARSELECT_vid,
  978.             BORDER, BOLD);
  979. load_vid(S.VAR_vid, init_display, 0, VAR_NUM_ELEMENTS, VAR_label);
  980. load_vid(S.KEY_vid, KEY_display, 0, KEY_NUM_ELEMENTS, KEY_label);
  981. load_vid(S.MES_vid, MES_display, 0, MES_NUM_ELEMENTS, MES_label);
  982. #if defined(vms)
  983. end_pasteboard_update();
  984. enable_trap(S.MES_vid);
  985. #endif
  986.  
  987. }
  988. void CDFLIST_special_options(screen)
  989. struct    GLOBAL_struct    *screen;
  990. {
  991. int     tcode;
  992. int    field_num;
  993. static char star[]  = "*";
  994. static char EPFIELD_mes[] =
  995. "Select desired EPOCH display format, Q to leave Special Option Window";
  996. /*
  997. static char noformat_mes[] =
  998. "This CDF does not a contain the attribute FORMAT, switching back to default";
  999. static char nofillval_mes[] =
  1000. "This CDF does not a contain the attribute FILLVAL, switching back to default";
  1001. */
  1002. #if defined(vms)
  1003. begin_pasteboard_update();
  1004. #endif
  1005.  
  1006. paste_virtual_display(S.SPECIAL_vid, SPECIAL_ROW_PASTE, SPECIAL_COL_PASTE);
  1007. label_border(S.SPECIAL_vid, SPECIAL_label, strlen(SPECIAL_label));
  1008. paste_virtual_display(S.EPOCHFORMAT_vid, EPOCHFORMAT_ROW_PASTE,
  1009.         EPOCHFORMAT_COL_PASTE);
  1010. load_vid(S.EPOCHFORMAT_vid, EPOCHFORMAT_display, 0,
  1011.     EPOCHFORMAT_NUM_ELEMENTS, EPOCHFORMAT_label);
  1012. /*
  1013. paste_virtual_display(S.VARFORMAT_vid, VARFORMAT_ROW_PASTE,
  1014.             VARFORMAT_COL_PASTE);
  1015. load_vid(S.VARFORMAT_vid, VARFORMAT_display, 0,
  1016.     VARFORMAT_NUM_ELEMENTS, VARFORMAT_label);
  1017.  
  1018. paste_virtual_display(S.FILTER_vid, FILTER_ROW_PASTE, FILTER_COL_PASTE);
  1019. load_vid(S.FILTER_vid, FILTER_display, 0, FILTER_NUM_ELEMENTS, FILTER_label);
  1020. paste_virtual_display(S.FILLVALUE_vid, FILLVALUE_ROW_PASTE,
  1021. FILLVALUE_COL_PASTE);
  1022. load_vid(S.FILLVALUE_vid, FILLVALUE_display, 0, FILLVALUE_NUM_ELEMENTS,
  1023.     FILLVALUE_label);
  1024. paste_virtual_display(S.MINMAX_vid, MINMAX_ROW_PASTE, MINMAX_COL_PASTE);
  1025. load_vid(S.MINMAX_vid, MINMAX_display, 0, MINMAX_NUM_ELEMENTS, MINMAX_label);
  1026. */
  1027. #if defined(vms)
  1028. end_pasteboard_update();
  1029. #endif
  1030.  
  1031. put_chars(S.EPOCHFORMAT_vid, star, 1, SO.EPOCH_format, 2, NOERASE, NORMAL);
  1032. /*
  1033. put_chars(S.VARFORMAT_vid, star, 1, SO.variable_format, 2, NOERASE, NORMAL);
  1034. put_chars(S.FILTER_vid, star, 1, SO.filters, 2, NOERASE, NORMAL);
  1035. put_chars(S.FILLVALUE_vid, star, 1, SO.fill_values, 2, NOERASE, NORMAL);
  1036. put_chars(S.MINMAX_vid, star, 1, SO.minmax, 2, NOERASE, NORMAL);
  1037. */
  1038. CDFLIST_special_keydef(screen);
  1039. tcode = CONTINUE;
  1040. field_num = EPOCHFORMAT_FIELD;
  1041. while(tcode != QUIT)
  1042.   {
  1043.   switch(field_num)
  1044.      {
  1045.      case EPOCHFORMAT_FIELD:
  1046.           CDFLIST_put_message(S.MES_vid, EPFIELD_mes, NOBELL, NORMAL,
  1047.                     NOPAUSE);
  1048.           tcode = CDFLIST_special_option_menu(S.EPOCHFORMAT_vid,
  1049.             &SO.EPOCH_format, EPOCHFORMAT_NUM_ELEMENTS);
  1050.           tcode = QUIT;
  1051.           break;
  1052.      }
  1053.    }
  1054.    /*
  1055.      case VARFORMAT_FIELD:
  1056.           tcode = CDFLIST_special_option_menu(S.VARFORMAT_vid,
  1057.             &SO.variable_format, VARFORMAT_NUM_ELEMENTS);
  1058.           if(!SO.format_attr && SO.variable_format == FORMAT)
  1059.          {
  1060.          SO.variable_format = NOFORMAT;
  1061.          CDFLIST_put_message(S.MES_vid, noformat_mes, RINGBELL, NORMAL,
  1062.                     PAUSE);
  1063.          CDFLIST_disp_opt(S.VARFORMAT_vid, SO.variable_format,
  1064.                 VARFORMAT_NUM_ELEMENTS);
  1065.          }
  1066.           break;
  1067.      case FILTER_FIELD:
  1068.           tcode = CDFLIST_special_option_menu(S.FILTER_vid,
  1069.             &SO.filters, FILTER_NUM_ELEMENTS);
  1070.           break;
  1071.      case FILLVALUE_FIELD:
  1072.           tcode = CDFLIST_special_option_menu(S.FILLVALUE_vid,
  1073.             &SO.fill_values, FILLVALUE_NUM_ELEMENTS);
  1074.           if(!SO.fillval_attr && SO.fill_values == FILLVAL)
  1075.          {
  1076.          SO.fill_values = NOFILLVAL;
  1077.          CDFLIST_put_message(S.MES_vid, nofillval_mes, RINGBELL,
  1078.                 NORMAL, PAUSE);
  1079.          CDFLIST_disp_opt(S.FILLVALUE_vid, SO.fill_values,
  1080.                 FILLVALUE_NUM_ELEMENTS);
  1081.          }
  1082.           break;
  1083.      case MINMAX_FIELD:
  1084.           tcode = CDFLIST_special_option_menu(S.MINMAX_vid,
  1085.             &SO.minmax, MINMAX_NUM_ELEMENTS);
  1086.           break;
  1087.       }
  1088.  
  1089.       field_num++;
  1090.     }
  1091. */
  1092. #if defined(vms)
  1093. begin_pasteboard_update();
  1094. #endif
  1095.         /*
  1096. unpaste_virtual_display(S.MINMAX_vid);
  1097. unpaste_virtual_display(S.FILLVALUE_vid);
  1098. unpaste_virtual_display(S.FILTER_vid);
  1099. unpaste_virtual_display(S.VARFORMAT_vid);
  1100. */
  1101. unpaste_virtual_display(S.EPOCHFORMAT_vid);
  1102. unpaste_virtual_display(S.SPECIAL_vid);
  1103. CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
  1104. #if defined(vms)
  1105. end_pasteboard_update();
  1106. #endif
  1107.  
  1108.  
  1109. }
  1110. int CDFLIST_special_option_menu(vid, value, num_rows)
  1111. WINDOWid    vid;
  1112. int        *value;
  1113. int        num_rows;
  1114. {
  1115. int        done;
  1116. int        row,col;
  1117. int        tcode;
  1118.  
  1119. done = FALSE;
  1120. row = *value;
  1121. col = 2;
  1122. while(!done)
  1123.   {
  1124.   set_cursor_abs(vid, row, col);
  1125. #ifdef vms
  1126.   read_input(&tcode);
  1127. #endif
  1128. #if defined(unix) | defined(__MSDOS__)
  1129.   read_input(vid, &tcode);
  1130. #endif
  1131.   switch(tcode)
  1132.      {
  1133.      case QUIT:
  1134.      case quit:
  1135.      case KB_CTRL_F:
  1136.           tcode = QUIT;
  1137.           done = TRUE;
  1138.           break;
  1139.      case KB_RETURN:
  1140.      case KB_PAD_ENTER:
  1141.           tcode = KB_RETURN;
  1142.           done = TRUE;
  1143.           break;
  1144.      case KB_UPARROW:
  1145.           row--;
  1146.           if(row < 1)row = num_rows;
  1147.           break;
  1148.      case KB_DOWNARROW:
  1149.           row++;
  1150.           if(row > num_rows)row = 1;
  1151.           break;
  1152.      case KB_REDRAW:
  1153.           redraw_screen();
  1154.           break;
  1155.       }
  1156.   CDFLIST_disp_opt(vid, row, num_rows);
  1157.   }
  1158.  
  1159. *value = row;
  1160. return(tcode);
  1161. }
  1162. void CDFLIST_disp_opt(vid, row, num_rows)
  1163. WINDOWid    vid;
  1164. int        row;
  1165. int        num_rows;
  1166. {
  1167. int        i;
  1168. static char star[]  = "*";
  1169. static char blank[] = " ";
  1170.  
  1171. for(i=1; i<=num_rows;i++)
  1172.       {
  1173.       if(i == row)
  1174.      put_chars(vid, star, 1, i, 2, NOERASE, NORMAL);
  1175.       else
  1176.      put_chars(vid, blank, 1, i, 2, NOERASE, NORMAL);
  1177.       }
  1178. }
  1179.  
  1180. #if defined(unix) | defined(__MSDOS__)
  1181. void CDFLIST_draw_main_screen(screen)
  1182. struct    GLOBAL_struct    *screen;
  1183. {
  1184. repaste_virtual_display(S.CDF_vid, CDF_ROW_PASTE, CDF_COL_PASTE);
  1185. repaste_virtual_display(S.VAR_vid, VAR_ROW_PASTE, VAR_COL_PASTE);
  1186. label_border(S.VAR_vid, VAR_label, strlen(VAR_label));
  1187. repaste_virtual_display(S.KEY_vid, KEY_ROW_PASTE, KEY_COL_PASTE);
  1188. label_border(S.KEY_vid, KEY_label, strlen(KEY_label));
  1189. repaste_virtual_display(S.MES_vid, MES_ROW_PASTE, MES_COL_PASTE);
  1190. label_border(S.MES_vid, MES_label, strlen(MES_label));
  1191. }
  1192. #endif
  1193.  
  1194. void CDFLIST_select_menu_item(vid, MES_vid, rvalue, display,
  1195. num_elements, num_rows, num_columns, row_start, col_start, mode, termcode)
  1196. WINDOWid    vid;
  1197. WINDOWid    MES_vid;
  1198. long int    *rvalue;
  1199. struct        vid_struct    display[];
  1200. long int    num_elements;
  1201. int        num_rows;
  1202. int        num_columns;
  1203. int        row_start;
  1204. int        col_start;
  1205. int        mode;
  1206. int        *termcode;
  1207. {
  1208. long int    in_value;
  1209. int        row, col;
  1210. int        tcode;
  1211. long int    done;
  1212. long int    num_screen;
  1213. long int    start_page;
  1214. long int    end;
  1215. long int    value;
  1216. int        row1 = 1;
  1217. int        col1 = 1;
  1218. static char    top[]    = "Top of menu";
  1219. static char    bottom[] = "Bottom of menu";
  1220.  
  1221. in_value = *rvalue;
  1222. /*
  1223. Find out the number of rows to be on the screen at one time
  1224. */
  1225. num_rows = num_rows - ROW_OFFSET;
  1226. num_columns = num_columns - COL_OFFSET;
  1227. if(num_elements > num_rows)
  1228.    num_screen = num_rows;
  1229. else
  1230.    num_screen = num_elements;
  1231. /*
  1232. Erase and load data into the menu for selection
  1233. */
  1234. value = 1;
  1235. row = 1;
  1236. col = 1;
  1237. #if !defined(vms)
  1238. begin_display_update(vid);
  1239. #endif
  1240. erase_display(vid, 1, 1, num_rows, num_columns);
  1241. load_menu(vid, display, num_screen, NO_label);
  1242. change_rendition(vid,1,1,num_rows,num_columns,NORMAL);
  1243. paste_virtual_display(vid, row_start, col_start);
  1244. #if !defined(vms)
  1245. end_display_update(vid);
  1246. #endif
  1247. start_page = 1;
  1248. if(mode == MENU)change_rendition(vid, row, col, 1, num_columns, REVERSE);
  1249. done = FALSE;
  1250. while(!done)
  1251.      {
  1252.      set_cursor_abs(vid, row, col);
  1253. #ifdef vms
  1254.      read_input(&tcode);
  1255. #endif
  1256. #if defined(unix) | defined(__MSDOS__)
  1257.      read_input(vid, &tcode);
  1258. #endif
  1259.      switch (tcode)
  1260.       {
  1261.       case KB_DOWNARROW:
  1262.            if(row == num_rows || value == num_elements)
  1263.           if(value < num_elements)
  1264.              {
  1265. /*
  1266. SCROLL UP
  1267. */
  1268.              value++; start_page++;
  1269.              begin_display_update(vid);
  1270.              erase_display(vid, row1, col1, num_rows, num_columns);
  1271.              load_menu(vid, display+(start_page-1),
  1272.              num_screen, NO_label);
  1273.              end_display_update(vid);
  1274.              }
  1275.           else
  1276.              {
  1277.              value = 1;
  1278.              row = 1;
  1279.              start_page = 1;
  1280.              begin_display_update(vid);
  1281.              erase_display(vid, 1, 1, num_rows, num_columns);
  1282.              load_menu(vid, display, num_screen, NO_label);
  1283.              end_display_update(vid);
  1284.              }
  1285.            else
  1286.           {
  1287.           row++; value++;
  1288.           }
  1289.            break;
  1290.       case KB_UPARROW:
  1291.            if(row > 1)
  1292.           {
  1293.              row--;
  1294.              value--;
  1295.           }
  1296.            else if(value > 1)
  1297.           {
  1298. /* 
  1299. SCROLL DOWN
  1300. */
  1301.              value--; start_page--;
  1302.              begin_display_update(vid);
  1303.              erase_display(vid, row1, col1, num_rows, num_columns);
  1304.              load_menu(vid, display+(start_page-1),
  1305.              num_screen, NO_label);
  1306.              end_display_update(vid);
  1307.           }
  1308.            else
  1309.           {
  1310.              start_page = num_elements - num_screen + 1;
  1311.              value = num_elements;
  1312.              row = num_screen;
  1313.              begin_display_update(vid);
  1314.              erase_display(vid, row1, col1, num_rows, num_columns);
  1315.              load_menu(vid, display+(start_page-1),
  1316.              num_screen, NO_label);
  1317.              end_display_update(vid);
  1318.           }
  1319.            break;
  1320. /*
  1321. PAGE DOWN
  1322. */
  1323.       case PAGEdown:
  1324.       case PAGEDOWN:
  1325.            start_page = start_page + num_screen;
  1326.            end = start_page + num_screen - 1;
  1327.            value = value + num_screen;
  1328.            if(end > num_elements)
  1329.           {
  1330. /*
  1331. Display the next page down
  1332. */
  1333.                   end = num_elements;
  1334.           start_page = end - num_screen + 1;
  1335.               value = num_elements;
  1336.           row = num_rows;
  1337.                 CDFLIST_put_message(MES_vid, bottom, NOBELL, NORMAL, NOPAUSE);
  1338.           }
  1339.            begin_display_update(vid);
  1340.            erase_display(vid, row1, col1, num_rows, num_columns);
  1341.            load_menu(vid, display+(start_page-1), num_screen, NO_label);
  1342.            end_display_update(vid);
  1343.            break;
  1344. /*
  1345. PAGE UP
  1346. */
  1347.       case PAGEUP:
  1348.       case PAGEup:
  1349.            start_page = start_page - num_screen;
  1350.            value = value - num_screen;
  1351.            if(start_page < 1)
  1352.           {
  1353.           start_page = 1;
  1354.           value = 1;
  1355.           row = 1;
  1356.           CDFLIST_put_message(MES_vid, top, NOBELL, NORMAL, NOPAUSE);
  1357.           }
  1358.            begin_display_update(vid);
  1359. /*
  1360. Display the next page up
  1361. */
  1362.            erase_display(vid, row1, col1, num_rows, num_columns);
  1363.            load_menu(vid, display+(start_page-1), num_screen, NO_label);
  1364.            end_display_update(vid);
  1365.            break;
  1366.       case KB_RETURN:
  1367.       case KB_PAD_ENTER:
  1368.            done = TRUE;
  1369.            *rvalue = value;
  1370.            *termcode = KB_RETURN;
  1371.            break;
  1372.       case QUIT:
  1373.       case quit:
  1374.            done = TRUE;
  1375.            *rvalue = in_value;
  1376.            *termcode = QUIT;
  1377.            break;
  1378.       case KB_CTRL_F:
  1379.            done = TRUE;
  1380.            *rvalue = value;
  1381.            *termcode = KB_CTRL_F;
  1382.            break;
  1383.       case KB_REDRAW:
  1384.            repaint_screen();
  1385.            break;
  1386.       default:
  1387.         break;
  1388.       }
  1389.       if(mode == MENU)
  1390.          {
  1391.          change_rendition(vid, 1, 1, num_rows, num_columns, NORMAL);
  1392.          change_rendition(vid, row, 1, 1, num_columns, REVERSE);
  1393.          }
  1394.       }
  1395. unpaste_virtual_display(vid);
  1396. }
  1397. void CDFLIST_CDF_info(screen, CDF, CDF_display, OUT_display)
  1398. struct    GLOBAL_struct    *screen;
  1399. struct    CDF_struct    *CDF;
  1400. struct  vid_struct    CDF_display[];
  1401. struct  vid_struct    OUT_display[];
  1402. {
  1403. char         string[21];                    /* V1.4 */
  1404. char        temp[7];                    /* V1.4 */
  1405. long int    i;
  1406. sprintf(string, "%ld ", C.num_dims);
  1407. CDFLIST_clear_row(S.CDF_vid, CDF_display, 2, 2, 28);
  1408. CDFLIST_put_selection(S.CDF_vid, CDF_display, NUMDIM_ELEMENT_NUM-1, string,
  1409.     2, REVERSE);
  1410. string[0] = '\0';
  1411. CDFLIST_clear_row(S.CDF_vid, CDF_display, 3, 3, 28);
  1412. if(C.num_dims > 0)
  1413.    {
  1414.    for (i=0; i < C.num_dims; i++)
  1415.         {
  1416.         sprintf(temp, "%ld ", C.dim_sizes[i]);
  1417.         strcat(string, temp);
  1418.         }
  1419.    }
  1420. else
  1421.     string[0] = '\0';
  1422. CDFLIST_put_selection(S.CDF_vid, CDF_display, DIMSIZ_ELEMENT_NUM-1, string,
  1423.     10, REVERSE);
  1424. sprintf(string, "%ld ", C.num_vars);
  1425. CDFLIST_clear_row(S.CDF_vid, CDF_display, 4, 4, 56);
  1426. CDFLIST_put_selection(S.CDF_vid, CDF_display, NUMVAR_ELEMENT_NUM-1, string,
  1427.     6, REVERSE);
  1428. sprintf(string, "%ld ", C.max_record_num+1);
  1429. CDFLIST_clear_row(S.CDF_vid, CDF_display, 5, 5, 53);
  1430. CDFLIST_put_selection(S.CDF_vid, CDF_display, NUMREC_ELEMENT_NUM-1, string,
  1431.     6, REVERSE);
  1432. CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM-1, 
  1433. OUT_display[C.output-1].label, 8, REVERSE);
  1434. }
  1435. void load_vid(vid, display, start_elem, num_elements, label)
  1436. WINDOWid         vid;
  1437. struct    vid_struct    display[];
  1438. int            start_elem;
  1439. int            num_elements;
  1440. char            label[];
  1441. {
  1442. long int        i;
  1443. int            len;
  1444. long int        end_elem;
  1445. int            erase_mode = NOERASE;
  1446. int            video_type = NORMAL;
  1447.  
  1448. len = strlen(label);
  1449. if(len > 0)label_border(vid, label, len);
  1450. end_elem = start_elem + num_elements;
  1451. for(i=start_elem; i< end_elem; i++)
  1452.     {
  1453.     len = strlen(display[i].label);
  1454.     put_chars(vid, display[i].label, len,
  1455.     display[i].row, display[i].col, erase_mode, video_type);
  1456.     }
  1457. }
  1458. void load_vars(vid, display, start_num, max_vars)
  1459. WINDOWid         vid;
  1460. struct    vid_struct    display[];
  1461. long int        start_num;
  1462. long int        max_vars;
  1463. {
  1464. long int        i;
  1465. int            len;
  1466. long int        erase_mode = NOERASE;
  1467. long int        video_type = NORMAL;
  1468. long int        elem;
  1469. int            row;
  1470. long int        bump;
  1471. long int        end_num;
  1472. end_num = start_num + 8;
  1473. begin_display_update(vid);
  1474. erase_display(vid, 2, 6, 9, VAR_COLUMNS-COL_OFFSET);
  1475. bump = 0;
  1476. row = 1;
  1477. for(i=start_num; i< end_num; i++)
  1478.     {
  1479.     elem = i<=max_vars ? i*3 : (i-max_vars)*3;
  1480.     if(elem >= 0 && elem <= 2)bump = 3;
  1481.     row++;
  1482.     len = strlen(display[elem+bump].label);
  1483.     if(len > 0)
  1484.        {
  1485.        put_chars(vid, display[elem+bump].label, len,
  1486.        row, display[elem+bump].col, erase_mode, video_type);
  1487.        change_rendition ( vid, row, 6, 1, len-6+1, REVERSE);
  1488.        len = strlen(display[elem+bump+1].label);
  1489.        put_chars(vid, display[elem+bump+1].label, len,
  1490.        row, display[elem+bump+1].col, erase_mode, video_type);
  1491.        len = strlen(display[elem+bump+2].label);
  1492.        put_chars(vid, display[elem+bump+2].label, len,
  1493.        row, display[elem+bump+2].col, erase_mode, video_type);
  1494.        }
  1495.     }
  1496. #if defined(vms)
  1497.     end_display_update(vid);
  1498. #else
  1499.     end_display_update_nobox(vid);
  1500. #endif
  1501. }
  1502. void load_vid_element(vid, display, element_num)
  1503. WINDOWid         vid;
  1504. struct    vid_struct    display[];
  1505. int            element_num;
  1506. {
  1507.  
  1508. int            len;
  1509.  
  1510. int            erase_mode = NOERASE;
  1511. int            video_type = NORMAL;
  1512.  
  1513. len = strlen(display[element_num-1].label);
  1514. put_chars(vid, display[element_num-1].label, len,
  1515. display[element_num-1].row, display[element_num-1].col, erase_mode, video_type);
  1516. }
  1517. void CDFLIST_load_keydef(vid, line1, line2)
  1518. WINDOWid         vid;
  1519. char            line1[];
  1520. char            line2[];
  1521. {
  1522. int            row, col;
  1523. int            erase_mode;
  1524. int            video_type;
  1525. int            len;
  1526. begin_display_update(vid);
  1527. erase_display(vid, 1, 1, KEY_ROWS-ROW_OFFSET, KEY_COLUMNS-COL_OFFSET);
  1528. row = 1; col = 1; erase_mode = ERASE; video_type = NORMAL;
  1529. len = strlen(line1);
  1530. if(len > (KEY_COLUMNS-COL_OFFSET))len = KEY_COLUMNS - COL_OFFSET;
  1531. put_chars(vid, line1, len, row, col, erase_mode, video_type);
  1532. len = strlen(line2);
  1533. row = 2; col = 1; erase_mode = ERASE; video_type = NORMAL;
  1534. if(len > (KEY_COLUMNS-COL_OFFSET))len = KEY_COLUMNS - COL_OFFSET;
  1535. put_chars(vid, line2, len, row, col, erase_mode, video_type);
  1536. #if defined(vms)
  1537. end_display_update(vid);
  1538. #else
  1539. end_display_update_nobox(vid);
  1540. #endif
  1541. }
  1542. void CDFLIST_put_selection(vid, display, element_num, selection,
  1543.             field_len, video_type)
  1544. WINDOWid         vid;
  1545. struct    vid_struct    display[];
  1546. int            element_num;
  1547. char            selection[];
  1548. int            field_len;
  1549. int            video_type;
  1550. {
  1551. int            len;
  1552.  
  1553. int            erase_mode = NOERASE;
  1554. int            row, col, end_col;
  1555.  
  1556. len = strlen(display[element_num].label);
  1557. row = display[element_num].row;
  1558. col = display[element_num].field_col;
  1559. len = strlen(selection);
  1560. end_col = col + field_len - 1;
  1561. erase_display(vid, row, col, row, end_col);
  1562. put_chars(vid, selection, len, row, col, erase_mode, video_type);
  1563. }
  1564. void CDFLIST_put_select_row(vid, display, row, element_num, selection,
  1565.         field_len, video_type)
  1566. WINDOWid         vid;
  1567. struct    vid_struct    display[];
  1568. int            row;
  1569. int            element_num;
  1570. char            selection[];
  1571. int            field_len;
  1572. int            video_type;
  1573. {
  1574. int        len;
  1575.  
  1576. int        erase_mode = NOERASE;
  1577. int        col, end_col;
  1578.  
  1579. len = strlen(display[element_num].label);
  1580. col = display[element_num].field_col;
  1581. len = strlen(selection);
  1582. end_col = col + field_len - 1;
  1583. erase_display(vid, row, col, row, end_col);
  1584. put_chars(vid, selection, len, row, col, erase_mode, video_type);
  1585. }
  1586. void CDFLIST_put_value(vid, display, row, element_num, bin_value)
  1587. WINDOWid         vid;
  1588. struct    vid_struct    display[];
  1589. int            row;
  1590. int            element_num;
  1591. double            bin_value;
  1592. {
  1593. char            value[20];
  1594. int            i;
  1595. int            len;
  1596.  
  1597. long int        erase_mode = NOERASE;
  1598. int            video_type = NORMAL;
  1599. int            col, end_col;
  1600.  
  1601. len = strlen(display[element_num].label);
  1602. col = display[element_num].col;
  1603. end_col = col + 20;
  1604. erase_display(vid, row, col, row, end_col);
  1605. if(bin_value < -1.e12 || bin_value >  1.e12)
  1606.    {
  1607.    sprintf(value,"%14.6e",bin_value);
  1608.    CDFLIST_left_justify(value);
  1609.    }
  1610. else
  1611.    {
  1612.    sprintf(value,"%f",bin_value);
  1613.    zero_replace(value);
  1614.    }
  1615. len = strlen(value);
  1616. for(i = len; i<14; i++)
  1617.     value[i] = ' ';
  1618. value[14] = '\0';
  1619. len = 14;
  1620. put_chars(vid, value, len, row, col, erase_mode, video_type);
  1621. strcpy(display[element_num].label, value);
  1622. }
  1623. void CDFLIST_put_TIME(vid, display, row, element_num, time)
  1624. WINDOWid         vid;
  1625. struct    vid_struct    display[];
  1626. int            row;
  1627. int            element_num;
  1628. double            time;
  1629. {
  1630. char            value[80];
  1631. int            len;
  1632.  
  1633. int            erase_mode = NOERASE;
  1634. int            video_type = NORMAL;
  1635. int            col, end_col;
  1636.  
  1637. len = EPOCH_WIDTH;
  1638. col = display[element_num].col;
  1639. end_col = col + EPOCH_WIDTH;
  1640. erase_display(vid, row, col, row, end_col);
  1641. ep.tSince0 = time;
  1642. strcpy(value, epochString(&ep));
  1643. put_chars(vid, value, len, row, col, erase_mode, video_type);
  1644. strcpy(display[element_num].label, value);
  1645. }
  1646. void CDFLIST_put_message(vid, message, rbell, video_type, pause)
  1647. WINDOWid         vid;
  1648. char            message[];
  1649. int            rbell;
  1650. int            video_type;
  1651. int            pause;
  1652. {
  1653. int            len;
  1654.  
  1655. int            erase_mode = ERASE;
  1656. int            row, col;
  1657. #if defined (vms)
  1658. float            wait = 3.; /*jtl*/
  1659. #endif
  1660.  
  1661. len = strlen(message);
  1662. row = 1;
  1663. col = 1;
  1664. if(rbell == RINGBELL)
  1665. #if defined(vms)
  1666.     ring_bell(vid);
  1667. #else
  1668.     ring_bell();
  1669. #endif
  1670. if(len > (MES_COLUMNS-COL_OFFSET))len = MES_COLUMNS - COL_OFFSET;
  1671. put_chars(vid, message, len, row, col, erase_mode, video_type);
  1672. if(pause == PAUSE)
  1673. #ifdef vms
  1674.              lib$wait(&wait);
  1675. #endif
  1676.  
  1677. #if defined(unix) | defined(__MSDOS__)
  1678.              sleep(3);
  1679. #endif
  1680.  
  1681. }
  1682. void load_menu(vid, display, num_elements, label)
  1683. WINDOWid         vid;
  1684. struct    vid_struct    display[];
  1685. int            num_elements;
  1686. char            label[];
  1687. {
  1688. int            i;
  1689. int            len;
  1690.  
  1691. int            erase_mode = NOERASE;
  1692. int            video_type = NORMAL;
  1693. int            row;
  1694. int            col = 1;
  1695. len = strlen(label);
  1696. if(len > 0)label_border(vid, label, len);
  1697. for(i=0; i< num_elements; i++)
  1698.     {
  1699.     row = i + 1;
  1700.     len = strlen(display[i].label);
  1701.     put_chars(vid, display[i].label, len, row, col,
  1702.     erase_mode, video_type);
  1703.     }
  1704. }
  1705. void zero_replace(string)
  1706. char        string[];
  1707. {
  1708. long int    zero_index;
  1709. long int    byte;
  1710. long int    found = FALSE;
  1711. long int    len;
  1712.  
  1713. CDFLIST_left_justify(string);
  1714. byte = 0;
  1715. len = strlen(string);
  1716. while(byte < len && !found)
  1717.       {
  1718.       if(string[byte] == PERIOD)found = TRUE;
  1719.       byte++;
  1720.       }
  1721. if(found)
  1722.    {
  1723.    zero_index = byte;
  1724.    while(byte < len)
  1725.       {
  1726.       if(string[byte] == '0')
  1727.       {
  1728.       if(zero_index == 0)zero_index = byte;
  1729.       }
  1730.       else
  1731.      zero_index = 0;
  1732.       byte++;
  1733.       }
  1734.    if(zero_index > 0)
  1735.      {
  1736.      for (byte=zero_index; byte<len; byte++)
  1737.       string[byte] = ' ';
  1738.      }
  1739.    }
  1740. }
  1741. void CDFLIST_check_name(string)
  1742. char        string[];
  1743. {
  1744. char        temp_name[14];
  1745. long int    byte;
  1746. long int    found;
  1747. CDFLIST_left_justify(string);
  1748. byte = 0;
  1749. while(string[byte] != '\0')
  1750.       {
  1751.       if(string[byte] == 32)string[byte] = '\0';
  1752.  byte++;
  1753.       }
  1754. byte = 0;
  1755.  
  1756. found = FALSE;
  1757. while(string[byte] != '\0' && !found)
  1758.       {
  1759.       if(string[byte] == PERIOD)
  1760.         {
  1761.         found = TRUE;
  1762.         temp_name[byte] = '\0';
  1763.         }
  1764.       else
  1765.         temp_name[byte] = string[byte];
  1766.       byte++;
  1767.       }        
  1768.  
  1769. temp_name[byte] = '\0';
  1770. strcpy(string, temp_name);
  1771. }
  1772. void CDFLIST_left_justify (field)
  1773.     char        field[];
  1774. {
  1775.     long int    i;
  1776.     long int    index;
  1777.     long int    done;
  1778.     char        *temp;
  1779.     long int    len;
  1780.     len = strlen(field);
  1781.     temp = (char *) malloc(len);                /* V1.5 */
  1782.     if(temp == NULL)return;
  1783. /* Blank out temporary hold area */
  1784.  
  1785.     for (i = 0; i < len; i++)
  1786.         temp[i] = ' ';
  1787.  
  1788.  
  1789.         done = FALSE;
  1790.         for (index = 0; done != TRUE && index <= len; index++)
  1791.  
  1792.             {
  1793. /* Look for a non-blank character */
  1794.  
  1795.             if(field[index] != ' ')
  1796.                 {
  1797. /* Left Justify by copying from the non-blank character to the end of field */
  1798.  
  1799.                 strncpy(temp,field+index,len-index);
  1800.                 for (i = 0; i < len; i++)
  1801.                     field[i] = ' ';
  1802.  
  1803. /* Now copy from the temporary field back to the permanent field */
  1804.  
  1805.                 strncpy(field, temp, len);
  1806.                 done = TRUE;
  1807.                   }
  1808.             }
  1809. free(temp);
  1810. }
  1811. void CDFLIST_print_header(select, num_select, max_term, output, fptr, first)
  1812. struct variable_struct  select[];
  1813. long int        num_select;
  1814. long int        max_term;
  1815. long int        output;
  1816. FILE            *fptr;
  1817. long int        first;
  1818. {
  1819. long int        i;
  1820. for (i = 0; i < num_select; i++)
  1821.     {
  1822.     if((output == TERMIN || output == TERMFILE) &&
  1823.        (i< max_term))
  1824. #if defined(vms)
  1825.       printf(" %s",select[i].header_name);
  1826. #endif
  1827. #if defined(unix) | defined(__MSDOS__)
  1828.       wprintw(stdscr," %s",select[i].header_name);
  1829. #endif
  1830.     if((output == FILEOUT || output == TERMFILE) && (first))
  1831.       fprintf(fptr," %s",select[i].header_name);
  1832.     }
  1833.     if(output == TERMIN || output == TERMFILE)
  1834. #ifdef vms
  1835.        printf("\n");
  1836. #endif
  1837. #if defined(unix) | defined(__MSDOS__)
  1838.        wprintw(stdscr,"\n");
  1839. #endif
  1840.     if((output == FILEOUT || output == TERMFILE) && (first))
  1841.     fprintf(fptr,"\n");
  1842. }
  1843. void CDFLIST_print_data(select, data_values, num_select, max_term,
  1844. output, fptr)
  1845. struct variable_struct  select[];
  1846. union mixed        data_values[];
  1847. long int        num_select;
  1848. long int        max_term;
  1849. long int        output;
  1850. FILE            *fptr;
  1851. {
  1852. long int        i;
  1853. double            value;
  1854. char            time[25];
  1855.  
  1856. for (i = 0; i < num_select; i++)
  1857.     {
  1858.     if(select[i].data_type == CDF_EPOCH)
  1859.      {
  1860.      ep.tSince0 = data_values[i].r8;
  1861.      if(SO.EPOCH_format == EPOCHFORM_DEF)
  1862.         strcpy(time, epochString(&ep));
  1863.      else
  1864.         strcpy(time, epochString1(&ep));
  1865.      if((output == TERMIN || output == TERMFILE) &&
  1866.         ( i< max_term))
  1867. #ifdef vms
  1868.            printf(" %s",time);
  1869. #endif
  1870. #if defined(unix) | defined(__MSDOS__)
  1871.            wprintw(stdscr," %s",time);
  1872. #endif
  1873.      if(output == FILEOUT|| output == TERMFILE)
  1874.            fprintf(fptr, " %s",time);
  1875.      }
  1876.     else if(select[i].data_type == CDF_CHAR ||
  1877.         select[i].data_type == CDF_UCHAR)
  1878.      {
  1879.      if((output == TERMIN || output == TERMFILE) &&
  1880.         (i< max_term))
  1881. #ifdef vms
  1882.            printf(" %s",data_values[i].string);
  1883. #endif
  1884. #if defined(unix) | defined(__MSDOS__)
  1885.            wprintw(stdscr," %s",data_values[i].string);
  1886. #endif
  1887.      if(output == FILEOUT|| output == TERMFILE)
  1888.            fprintf(fptr, " %s",data_values[i].string);
  1889.      }
  1890.     else
  1891.     {
  1892.     switch(select[i].data_type)
  1893.        {
  1894.        case CDF_REAL4:
  1895.        case CDF_FLOAT:
  1896.         value = (double) data_values[i].r4;
  1897.         if((output == TERMIN || output == TERMFILE) &&
  1898.           ( i< max_term))
  1899.            {
  1900. #if defined(vms)
  1901.            if(value < -1.e12 ||
  1902.               value >  1.e12)
  1903.               printf(" %13.6e",value);
  1904.            else
  1905.               printf(" %13.*f",precision(value),value);
  1906. #endif
  1907. #if defined(unix) | defined(__MSDOS__)
  1908.            if(value < -1.e12 ||
  1909.               value >  1.e12)
  1910.               wprintw(stdscr," %13.6e",value);
  1911.            else
  1912.               wprintw(stdscr," %13.*f",precision(value),value);
  1913. #endif
  1914.            }
  1915.         if(output == FILEOUT|| output == TERMFILE)
  1916.            {
  1917.            if(value < -1.e12 ||
  1918.               value >  1.e12)
  1919.               fprintf(fptr," %13.6e",value);
  1920.            else
  1921.               fprintf(fptr, " %13.*f",precision(value), value);
  1922.            }
  1923.         break;
  1924.        case CDF_REAL8:
  1925.        case CDF_DOUBLE:
  1926.         value = data_values[i].r8;
  1927.         if((output == TERMIN || output == TERMFILE) &&
  1928.           ( i< max_term))
  1929.            {
  1930. #ifdef vms
  1931.            if(value < -1.e12 ||
  1932.               value >  1.e12)
  1933.               printf(" %13.6e",value);
  1934.            else
  1935.               printf(" %13.*f",precision(value),value);
  1936. #endif
  1937. #if defined(unix)   | defined(__MSDOS__)
  1938.            if(value < -1.e12 ||
  1939.               value >  1.e12)
  1940.               wprintw(stdscr," %13.6e",value);
  1941.            else
  1942.               wprintw(stdscr," %13.*f",precision(value),value);
  1943. #endif
  1944.            }
  1945.         if(output == FILEOUT|| output == TERMFILE)
  1946.            {
  1947.            if(value < -1.e12 ||
  1948.               value >  1.e12)
  1949.               fprintf(fptr," %13.6e",value);
  1950.            else
  1951.               fprintf(fptr, " %13.*f",precision(value), value);
  1952.            }
  1953.         break;
  1954.        case CDF_INT4:
  1955.         if((output == TERMIN || output == TERMFILE) &&
  1956.            (i< max_term))
  1957. #ifdef vms
  1958.            printf(" %11ld  ",data_values[i].i4);
  1959. #endif
  1960. #if defined(unix) | defined(__MSDOS__)
  1961.            wprintw(stdscr," %11ld  ",data_values[i].i4);
  1962. #endif
  1963.         if(output == FILEOUT|| output == TERMFILE)
  1964.            fprintf(fptr, " %11ld  ",data_values[i].i4);
  1965.         break;
  1966.        case CDF_UINT4:
  1967.         if((output == TERMIN || output == TERMFILE) &&
  1968.            (i< max_term))
  1969. #ifdef vms
  1970.            printf("  %10lu  ",data_values[i].ui4);
  1971. #endif
  1972. #if defined(unix) | defined(__MSDOS__)
  1973.            wprintw(stdscr,"  %10lu  ",data_values[i].ui4);
  1974. #endif
  1975.         if(output == FILEOUT|| output == TERMFILE)
  1976.            fprintf(fptr, "  %10lu  ",data_values[i].ui4);
  1977.         break;
  1978.        case CDF_INT2:
  1979.         if((output == TERMIN || output == TERMFILE) &&
  1980.            (i< max_term))
  1981. #ifdef vms
  1982.            printf("      %6d  ",data_values[i].i2);
  1983. #endif
  1984. #if defined(unix) | defined(__MSDOS__)
  1985.            wprintw(stdscr,"      %6d  ",data_values[i].i2);
  1986. #endif
  1987.         if(output == FILEOUT|| output == TERMFILE)
  1988.            fprintf(fptr,"      %6d  ",data_values[i].i2);
  1989.         break;
  1990.        case CDF_UINT2:
  1991.         if((output == TERMIN || output == TERMFILE) &&
  1992.            (i< max_term))
  1993. #ifdef vms
  1994.            printf("      %6u  ",data_values[i].ui2);
  1995. #endif
  1996. #if defined(unix) | defined(__MSDOS__)
  1997.            wprintw(stdscr,"      %6u  ",data_values[i].ui2);
  1998. #endif
  1999.         if(output == FILEOUT|| output == TERMFILE)
  2000.            fprintf(fptr,"      %6u  ",data_values[i].ui2);
  2001.         break;
  2002.        case CDF_BYTE:
  2003.        case CDF_INT1:
  2004.         if((output == TERMIN || output == TERMFILE) &&
  2005.            (i< max_term))
  2006. #ifdef vms
  2007.            printf("       %4d   ",data_values[i].byte);
  2008. #endif
  2009. #if defined(unix) | defined(__MSDOS__)
  2010.            wprintw(stdscr,"       %4d   ",data_values[i].byte);
  2011. #endif
  2012.         if(output == FILEOUT|| output == TERMFILE)
  2013.            fprintf(fptr,"       %4d   ",data_values[i].byte);
  2014.         break;
  2015.        case CDF_UINT1:
  2016.         if((output == TERMIN || output == TERMFILE) &&
  2017.            (i< max_term))
  2018. #ifdef vms
  2019.            printf("        %3u   ",data_values[i].ubyte);
  2020. #endif
  2021. #if defined(unix) | defined(__MSDOS__)
  2022.            wprintw(stdscr,"        %3u   ",data_values[i].ubyte);
  2023. #endif
  2024.         if(output == FILEOUT|| output == TERMFILE)
  2025.            fprintf(fptr,"        %3u   ",data_values[i].ubyte);
  2026.        }
  2027.        }
  2028.     }
  2029.     if(output == TERMIN || output == TERMFILE)
  2030. #ifdef vms
  2031.        printf("\n");
  2032. #endif
  2033. #if defined(unix) | defined(__MSDOS__)
  2034.        wprintw(stdscr,"\n");
  2035. #endif
  2036.     if(output == FILEOUT || output == TERMFILE)
  2037.        fprintf(fptr,"\n");
  2038. }
  2039. void CDFLIST_var_menus(screen, CDF, var_rows, var_columns)
  2040. struct    GLOBAL_struct    *screen;
  2041. struct    CDF_struct    *CDF;
  2042. int            *var_rows;
  2043. int            *var_columns;
  2044. {
  2045. /*
  2046. create the virtual display for the variables in the CDF, number of rows
  2047. depends on the the number of variables, add 1 for select_var option
  2048. */
  2049. if((C.num_vars+ROW_OFFSET+1) > VARSELECT_ROWS)
  2050.    *var_rows = VARSELECT_ROWS;
  2051. else
  2052.    *var_rows = C.num_vars + ROW_OFFSET + 1;
  2053. if((C.max_var_len+COL_OFFSET) > VARSELECT_COLUMNS)
  2054.    *var_columns = VARSELECT_COLUMNS;
  2055. else
  2056.    *var_columns = C.max_var_len+COL_OFFSET;
  2057. create_virtual_display(*var_rows, *var_columns,
  2058.                &S.VARSELECT_vid, BORDER, BOLD);
  2059. }
  2060. CDFstatus CDFLIST_close(CDF)
  2061. struct    CDF_struct    *CDF;
  2062. {
  2063. CDFstatus        rcode;
  2064.  
  2065. rcode = CDFclose(C.CDF_id);
  2066.  
  2067. return(rcode);
  2068. }
  2069. void CDFLIST_close_screen()
  2070. {
  2071. delete_pasteboard(ERASE);
  2072. }
  2073. double r4_r8(r4_ptr)
  2074. float    *r4_ptr;
  2075. {
  2076. float    r4;
  2077. /*
  2078. Convert float to double
  2079. Based on assumption that float contains 7 significant digits
  2080. */
  2081. double        r4r8;
  2082. double         fracr8;
  2083. float          realexp,temp,rfrac,x;
  2084. double        base, power,exp;
  2085. long int     frac;
  2086. long int     evalue;
  2087. r4 = *r4_ptr;
  2088. /*
  2089. If the REAL*4 value is 0 then just set the REAL*8 value to 0 and return
  2090. */
  2091. if(r4 == 0.) return(0.);
  2092.  
  2093. temp = r4;
  2094. evalue  = 0;
  2095. /*
  2096. Calculate the exponent of the incoming REAL*4 value
  2097. If absolute value ge 10 exponent is positive
  2098. If absolute value lt 1  exponent is negative
  2099. */
  2100. if(fabs(temp) >= 10.)
  2101.     {
  2102.     while(fabs(temp) >= 10.)
  2103.           {
  2104.           evalue = evalue + 1;
  2105.           temp = temp / 10.;
  2106.           }
  2107.     }
  2108. else if(fabs(temp) < 1.)
  2109.  
  2110.     {
  2111.     while(fabs(temp) < 1.)
  2112.           {
  2113.           evalue = evalue - 1;
  2114.           temp = temp * 10.;
  2115.           }
  2116.  
  2117.     }
  2118. /*
  2119. Extract out the fractional portion of the real value
  2120. */
  2121. /*
  2122. exp = (long int) r4;
  2123. realexp =  (float) exp;
  2124. rfrac = r4-realexp;
  2125. */
  2126. if(r4 > 0.)
  2127.    exp = floor(r4);
  2128. else
  2129.    exp = ceil(r4);
  2130. realexp = (float) exp;
  2131. rfrac = r4 - realexp;
  2132. /*
  2133. Convert significant digits of fraction portion to integer by multiplying.
  2134. */
  2135. base = 10.;
  2136. power = (double) (6-evalue);
  2137. x = rfrac*pow(base,power);
  2138. if(x > 0.)
  2139.    frac = (long int) (x + .5);
  2140. else
  2141.    frac = (long int) (x - .5);
  2142. fracr8 = (double) frac;
  2143. r4r8 = exp;
  2144. /*
  2145. Convert the integer back into a fraction by diving.
  2146. then ADD back in the integer portion.
  2147. */
  2148. r4r8 = r4r8 + fracr8/(pow(base, power));
  2149. return(r4r8);
  2150. }
  2151. void CDFLIST_valid_minmax (CDF_id, attr_num, field_num, scale, rcode)
  2152.  
  2153.     CDFid      CDF_id;
  2154.     long       attr_num;
  2155.     long       field_num;
  2156.     double      *scale;
  2157.     CDFstatus *rcode;
  2158. {
  2159.     float            r4;
  2160.     long int        i4;
  2161.     unsigned long int    ui4;
  2162.     short int        i2;
  2163.     unsigned short int    ui2;
  2164.     Schar                   byte;
  2165.     Uchar                ubyte;
  2166.     long             data_type;
  2167.     long             num_elements;
  2168.  
  2169.     *rcode = CDFattrEntryInquire(CDF_id, attr_num, field_num, &data_type,
  2170.         &num_elements);
  2171.     if(*rcode < CDF_OK) return;
  2172.     switch(data_type)
  2173.            {
  2174.            case CDF_REAL4:
  2175.            case CDF_FLOAT:
  2176.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &r4);
  2177.             *scale = r4_r8(&r4);
  2178.            break;
  2179.            case CDF_REAL8:
  2180.            case CDF_DOUBLE:
  2181.            case CDF_EPOCH:
  2182.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, scale);
  2183.            break;
  2184.            case CDF_INT4:
  2185.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &i4);
  2186.             *scale = (double) i4;
  2187.            break;
  2188.            case CDF_UINT4:
  2189.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &ui4);
  2190.             *scale = (double) ui4;
  2191.            break;
  2192.            case CDF_INT2:
  2193.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &i2);
  2194.             *scale = (double) i2;
  2195.            break;
  2196.            case CDF_UINT2:
  2197.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &ui2);
  2198.             *scale = (double) ui2;
  2199.            break;
  2200.            case CDF_BYTE:
  2201.            case CDF_INT1:
  2202.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &byte);
  2203.             *scale = (double) byte;
  2204.            break;
  2205.            case CDF_UINT1:
  2206.             *rcode = CDFattrGet(CDF_id, attr_num, field_num, &ubyte);
  2207.             *scale = (double) ubyte;
  2208.            }
  2209. }
  2210. void init_var_display(display, num_vars)
  2211. struct    vid_struct     *display;
  2212. long int         num_vars;
  2213. {
  2214. long int    i;
  2215. long int    num;
  2216. long int    index;
  2217. char        temp[10];
  2218. display[0].row = 1;
  2219. display[0].col = 6;
  2220. strcpy(display[0].label, "Variable");
  2221. display[0].field_col = 6;
  2222. display[1].row = 1;
  2223. display[1].col = 26;
  2224. strcpy(display[1].label, "Minimum");
  2225. display[1].field_col = 26;
  2226. display[2].row = 1;
  2227. display[2].col = 52;
  2228. strcpy(display[2].label, "Maximum");
  2229. display[2].field_col = 52;
  2230. if(num_vars < 8)
  2231.    num = 8;
  2232. else
  2233.    num = num_vars;
  2234.  
  2235. for(i=1; i<=num; i++)
  2236.     {
  2237.     index = (i-1)*3;
  2238.     display[index+3].row = i+1;
  2239.     display[index+3].col = 1;
  2240.     sprintf(temp, "%3ld) ",i);
  2241.     strcpy(display[index+3].label, temp);
  2242.     display[index+3].field_col = 6;
  2243.     display[index+4].row = i+1;
  2244.     display[index+4].col = 26;
  2245.     display[index+4].label[0] = '\0';
  2246.     display[index+4].field_col = 26;
  2247.     display[index+5].row = i+1;
  2248.     display[index+5].col = 52;
  2249.     display[index+5].label[0] = '\0';
  2250.     display[index+5].field_col = 52;
  2251.     }
  2252. }
  2253.